<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
include("../../Connections/connect_client.php");
if(isset($_SESSION['captcha'])&& isset($_GET['captcha'])&&isset($_GET['votedetailid']))
{
	if ($_SESSION['captcha']==$_GET['captcha'] )
	{
		$query="UPDATE votedetail SET AgreeNum = AgreeNum+1 WHERE VoteDetailID=".intval($_GET['votedetailid']);
		mysql_query($query);
	}
	else
	{
		header('location:../captcha/confirm.php?e=0&answer='.$_GET['votedetailid']);
	}
}
?>

<?php 
	if(isset($_GET['voteid']))
	$vote=intval($_GET['voteid']);
	if(isset($_GET['votedetailid']))
	{
		$query="SELECT * FROM votedetail v WHERE v.VoteDetailID=".intval($_GET['votedetailid']);
		$res=mysql_query($query);
		$vtdetail=mysql_fetch_assoc($res);
		$vote=$vtdetail['VoteID'];
	}
  	
	$query="SELECT v.VoteID,v.Content, sum(v2.AgreeNum) AS Total FROM vote v INNER JOIN votedetail v2 ON v2.VoteID = v.VoteID  WHERE v.VoteID=$vote GROUP BY v.VoteID";
	$resvote=mysql_query($query);
	$vt=mysql_fetch_assoc($resvote);
	$total=$vt["Total"];
	
?>

<table width="465px" border="1" cellspacing="0" cellpadding="5" class="table table-striped" >
  <tr>
    <td colspan="3"><strong><?php echo $vt["Content"]; ?></strong></td>
  </tr>
  <?php
  	
	$query="SELECT * FROM votedetail v WHERE v.VoteID=$vote ORDER BY v.OrderIndex";
	$res=mysql_query($query);
	while($row=mysql_fetch_assoc($res))
	{
		if($total==0)
		$per=0;
		else
		$per=round(intval($row["AgreeNum"]) / $total,3)*100;
		
  ?>
  <tr>
    <td><?php echo $row["Content"]; ?></td>
    <td><div style="width:200px; height:10px; background-color:#CCC" ><div style=" background-color:#F00; height:10px; width:<?php echo $per; ?>%"></div></div> <?php echo $per." %"; ?></td>
    <td><?php echo $row["AgreeNum"]." phiếu"; ?> </td>
  </tr>
  <?php 
	}
	?>
  <tr>
    <td>&nbsp;</td>
    <td style="text-align:right">Tổng cộng</td>
    <td><?php echo $total." phiếu"; ?></td>
  </tr>
</table>



</body>
</html>
